﻿@using ZBJF.Warranty.WebProvider
@{
    ViewBag.Title = "Index";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
<ul class="nav nav-tabs">
    <li class="active"><a href="/ServiceProvider/ServiceProviderIndex">服务商列表</a></li>
    <li class="Add-R"><a href="/ServiceProvider/ServiceProviderEdit/0">添加服务商</a></li>
</ul>
<form id="searchForm" class="breadcrumb form-search">
    <div>
        <label>服务商类型：</label>
        @Html.DropDownList("serviceProviderTypeCode", ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ZBJF.Warranty.Common.Enums.Base.ServiceProductType)))
        <label>服务商名称：</label>
        <input id="serviceProviderName" name="serviceProviderName" class="input-medium" placeholder="请输入服务商名称" type="text" value="" maxlength="50" />
        <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">
    </div>
</form>
<div class="table-responsive dataTables_wrapper">
    <table id="serviceProviderList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="100">服务商名称</th>
                <th width="100">服务商编码</th>
                <th width="100">服务商类型</th>
                <th width="100">账户名称</th>
                <th width="100">开户行</th>
                <th width="100">账号</th>
                <th width="80">联系电话</th>
                <th width="60">是否启用</th>
                <th width="40">操作</th>
            </tr>
        </thead>
    </table>
</div>
@section scripts{
    @Scripts.Render("~/Bundles/ImagePreview")
    <script type="text/javascript">
        var isSearch = false;
        $(function () {
            var objTable = $("#serviceProviderList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/ServiceProvider/ServiceProviderList",
                    aoColumns: [
                        {
                            "mData": null, "bSortable": false, "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        {
                            "mData": "ServiceProviderName", "bSortable": false, "fnRender": function (nRow) {
                                return "<a class='Edit-R' href='/ServiceProvider/ServiceProviderEdit/" + nRow.aData.ID + "' title='edit'>" + nRow.aData.ServiceProviderName + "</a>";
                            }
                        },
                        { "mData": "ServiceCode", "bSortable": false },
                        { "mData": null, "bSortable": false },                     
                        { "mData": "BankName", "bSortable": false },
                        { "mData": "BankAccountName", "bSortable": false },
                        { "mData": "BankAccount", "bSortable": false },
                         { "mData": "ContactPhone", "bSortable": false },
                         { "mData": "IsAvailable" },
                        { "mData": "ID", "bSortable": false }
                    ],
                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        $('td:eq(8)', nRow).html(aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon);
                        var html = "<a class='Edit-R' href='/ServiceProvider/ServiceProviderEdit/" + aData.ID + "' title='edit'><i class='icon-edit'></i></a>";
                        html += "<a class='Edit-R' href=\"javascript:UpdateStatus('" + aData.ID + "'," + !aData.IsAvailable + ",'/ServiceProvider/ServiceProviderUpdateStatus','serviceProviderList')\" title='" + (aData.IsAvailable ? "禁用" : "启用") + "'>" + (aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                        $('td:eq(9)', nRow).html(html);

                        if (aData.ServiceProviderTypeList && aData.ServiceProviderTypeList.length > 0) {
                            var serviceType = "";
                            aData.ServiceProviderTypeList.forEach(function (item, index) {
                                serviceType += item.ServiceProviderTypeName + ","
                                if (++index % 3 == 0)
                                    serviceType += "\r\n";
                            })
                            $('td:eq(3)', nRow).html(serviceType);
                        }
                    }
                });
            imgPreview();
        });

        function imgPreview() {
            setTimeout(function () { $("img.preview").preview(); }, 500);
        }
        function search() {
            /*给查询对象赋值*/
            queryParamList.ServiceProviderTypeCode = $("#serviceProviderTypeCode").val();
            queryParamList.ServiceProviderName = $("#serviceProviderName").val();
            $("#serviceProviderList").dataTable().fnDraw();
            imgPreview();
        }

    </script>
}


